Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Latest commit

 

History

History
22 lines (18 loc) · 1.05 KB

3.3.3 - Coroutine/Client->recv.md

File metadata and controls

22 lines (18 loc) · 1.05 KB

Coroutine\Client->recv

recv方法用于从服务器端接收数据。底层会自动yield,等待数据接收完成后自动切换到当前协程。

function Coroutine\Client->recv(float $timeout = -1) : string;
  • recv方法,不接受长度参数
    • 设置了通信协议,recv会返回完整的数据,长度受限于package_max_length
    • 未设置通信协议,recv最大返回64K数据
  • 未设置通信协议返回原始的数据,需要PHP代码中自行实现网络协议的处理
  • 服务端主动关闭连接,recv返回空字符串
  • recv操作需要进行一次协程切换,在收到数据后进行resume
  • $timeout 设置超时,单位为秒,浮点型,需要2.1.2或更高版本

超时设置

  • 传入了$timeout,优先使用制定的timeout参数
  • 未传入$timeout,但在connect时指定了超时时间,自动以connect超时时间作为recv超时时间
  • 未传入$timeout,未设置connect超时,将设置为-1表示永不超时
  • 发生超时的错误码为ETIMEDOUT